package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.domain.Region;
import cn.wolfcode.luowowo.domain.Strategy;
import cn.wolfcode.luowowo.domain.StrategyCatalog;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.service.IRegionService;
import cn.wolfcode.luowowo.service.IStrategyService;
import cn.wolfcode.luowowo.service.ITravelService;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//目的地控制器
@RestController
@RequestMapping("destinations")
public class DestinationController {
    //注入目的地业务
    @Autowired
    private IDestinationService destinationService;
    //注入区域业务
    @Autowired
    private IRegionService regionService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;
    //获取热门区域信息
    @GetMapping("/hotRegion")
    public Object hotRegion(){
        List<Region> list = regionService.hotRegion();
        return JsonResult.success(list);
    }

    //根据区域id搜索关联目的地信息的所有子目的地
    @GetMapping("/search")
    public Object search(String regionId){
        List<Destination> list = destinationService.getDestByRegionIdForApi(regionId);
        //list.forEach(System.err::println);
        return JsonResult.success(list);
    }
    //吐司
    @GetMapping("/toasts")
    public Object toasts(String destId){
        List<Destination> list = destinationService.getToasts(destId);
        return JsonResult.success(list);
    }
    //目的地信息
    @GetMapping("/detail")
    public Object detail(String id){
        Destination destination = destinationService.get(id);
        return JsonResult.success(destination);
    }
    //目的地下的攻略分类目录
    @GetMapping("/catalogs")
    public Object catalogs(String destId){
        List<StrategyCatalog> catalogs = destinationService.catalogs(destId);
        return JsonResult.success(catalogs);
    }
    //目的地下点击量前3的攻略文章
    @GetMapping("/strategies/viewnumTop3")
    public Object viewnumTop3(String destId){
        List<Strategy> list = strategyService.viewnumTop3(destId);
        return JsonResult.success(list);
    }

    //目的地下点击量前3的攻略文章
    @GetMapping("/travels/viewnumTop3")
    public Object travelsViewnumTop3(String destId){
        List<Strategy> list = travelService.viewnumTop3(destId);
        return JsonResult.success(list);
    }
}

